﻿using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;

namespace AuchanScan.Datas
{
    public class DataHelper
    {
        public static Offre JTokenToOffre(JToken token)
        {
            var o = new Offre();

            o.Id = int.Parse(token["r"].ElementAt(0).ToString());
            JToken[] RayonIds = token["r"].ElementAt(1).ToArray();
            if (RayonIds != null && RayonIds.Length > 0)
            {
                o.RayonIds = new List<int>();
                foreach (JToken item in RayonIds)
                {
                    o.RayonIds.Add(int.Parse(item.ToString()));
                }
            }

            o.PageVL = int.Parse(token["r"].ElementAt(2).ToString());
            o.Position = int.Parse(token["r"].ElementAt(3).ToString());
            o.Nom1 = token["r"].ElementAt(4).ToString();
            o.Nom2 = token["r"].ElementAt(5).ToString();
            o.Price = double.Parse(token["r"].ElementAt(6).ToString());
            o.StrikePrice = double.Parse(token["r"].ElementAt(7).ToString());
            o.EuroCagnotte = double.Parse(token["r"].ElementAt(8).ToString());
            o.EuroPercent = double.Parse(token["r"].ElementAt(9).ToString());
            o.Comment1 = token["r"].ElementAt(10).ToString();
            o.Comment2 = token["r"].ElementAt(11).ToString();
            o.Comment3 = token["r"].ElementAt(12).ToString();
            o.FreeMecanic = token["r"].ElementAt(13).ToString();
            o.IsComplex = Convert.ToBoolean((int) token["r"].ElementAt(14));
            o.TractId = int.Parse(token["r"].ElementAt(15).ToString());
            o.StartDate = token["r"].ElementAt(16).ToString().Replace(" 00:00:00", "");
            o.EndDate = token["r"].ElementAt(17).ToString().Replace(" 00:00:00", "");
            o.Order = int.Parse(token["r"].ElementAt(18).ToString());
            o.ContainSpecialStuff = Convert.ToBoolean((int) token["r"].ElementAt(19));


            return o;
        }

        public static Rayon JTokenToRayon(JToken token)
        {
            var r = new Rayon();

            r.Id = int.Parse(token["r"].ElementAt(0).ToString());
            r.Name = token["r"].ElementAt(1).ToString();
            r.Order = int.Parse(token["r"].ElementAt(2).ToString());
            r.TractId = int.Parse(token["r"].ElementAt(3).ToString());

            return r;
        }

        public static Tract JTokenToTract(JToken token)
        {
            var t = new Tract();
            t.Id = int.Parse(token["r"].ElementAt(0).ToString());
            t.Name = token["r"].ElementAt(1).ToString();
            t.IsSpecial = Convert.ToBoolean((int) token["r"].ElementAt(2));
            t.StartDate = token["r"].ElementAt(3).ToString().Replace(" 00:00:00", "");
            t.EndDate = token["r"].ElementAt(4).ToString().Replace(" 00:00:00", "");

            return t;
        }

        public static List<Magasin> GetMagasins()
        {
            var magasins = new List<Magasin>();

            #region m1

            var m1 = new Magasin();
            m1.Id = 1;
            m1.Address = "C.Cial Villebon 2, Chemin de Briis";
            m1.Name = "Auchan Villebon/Yvette";
            m1.Code = "AVY";
            m1.Department = "91";
            m1.Longitude = 2.25999;
            m1.Latitude = 48.70968;
            m1.Phone = "01.69.31.62.00";
            m1.Country = "Villebon/Yvette";
            m1.PostCode = "91141";
            m1.Hours = @"De lundi au vendredi de 08h30 à 22h00.
            Le samedi de 08h00 à 22h00";

            #endregion

            #region m2

            var m2 = new Magasin();
            m2.Id = 2;
            m2.Address = "C.Cial Maison Neuve, D19";
            m2.Name = "Auchan Bretigny-s/Orge";
            m2.Code = "AVY";
            m2.Department = "91";
            m2.Longitude = 2.30228;
            m2.Latitude = 48.58628;
            m2.Phone = "01.69.31.62.00";
            m2.Country = "Bretigny-s/Orge";
            m2.PostCode = "91141";
            m2.Hours = @"De lundi au vendredi de 08h30 à 22h00.
            Le samedi de 08h00 à 22h00";

            #endregion

            #region m3

            var m3 = new Magasin();
            m3.Id = 3;
            m3.Address = "C.Cial Val d Oly, 8 rue de la Longueraie";
            m3.Name = "Auchan Vigneux, Montgeron";
            m3.Code = "AVY";
            m3.Department = "91";
            m3.Longitude = 2.43788;
            m3.Latitude = 48.71473;
            m3.Phone = "01.69.31.62.00";
            m3.Country = "Vigneux, Montgeron";
            m3.PostCode = "91141";
            m3.Hours = @"De lundi au vendredi de 08h30 à 22h00.
            Le samedi de 08h00 à 22h00";

            #endregion

            #region m4

            var m4 = new Magasin();
            m4.Id = 4;
            m4.Address = "C.Cial des 3 Moulins, 1 av Aristide Briand";
            m4.Name = "Auchan Issy-les-Moulineaux";
            m4.Code = "AVY";
            m4.Department = "91";
            m4.Longitude = 2.25125;
            m4.Latitude = 48.82075;
            m4.Phone = "01.69.31.62.00";
            m4.Country = "Issy-les-Moulineaux";
            m4.PostCode = "91141";
            m4.Hours = @"De lundi au vendredi de 08h30 à 22h00.
            Le samedi de 08h00 à 22h00";

            #endregion

            #region m5

            var m5 = new Magasin();
            m5.Id = 5;
            m5.Address = "La Défense, Les 4 Temps, Le Parvis de la Défense";
            m5.Name = "Auchan Puteaux";
            m5.Code = "AVY";
            m5.Department = "91";
            m5.Longitude = 2.23837;
            m5.Latitude = 48.89070;
            m5.Phone = "01.69.31.62.00";
            m5.Country = "Puteaux";
            m5.PostCode = "91141";
            m5.Hours = @"De lundi au vendredi de 08h30 à 22h00.
            Le samedi de 08h00 à 22h00";

            #endregion

            #region m6

            var m6 = new Magasin();
            m6.Id = 6;
            m6.Address = "26 avenue du Général De Gaulle";
            m6.Name = "Auchan Bagnolet";
            m6.Code = "AVY";
            m6.Department = "91";
            m6.Longitude = 2.41509;
            m6.Latitude = 48.86558;
            m6.Phone = "01.69.31.62.00";
            m6.Country = "Bagnolet";
            m6.PostCode = "91141";
            m6.Hours = @"De lundi au vendredi de 08h30 à 22h00.
            Le samedi de 08h00 à 22h00";

            #endregion

            magasins.Add(m1);
            magasins.Add(m2);
            magasins.Add(m3);
            magasins.Add(m4);
            magasins.Add(m5);
            magasins.Add(m6);

            return magasins;
        }
    }
}